
const Count = {
  namespaced: true,
  state: () => ({
    count: 0,
  }),
  mutations: {
    addWait(state) {
      state.count++;
    },
    addOdd(state) {
      state.count++;
    },
    increment(state) {
      //state 传进来的默认参数是不同的,
      //取属性使用，this.$store.state.count
      state.count--;
    },
    decrement(state) {
      console.log(state);
      //取属性使用，this.$store.state.count
      state.count++;
    },
  },
  actions: {
    addWait(context) {
      //这里必须写this才能够取到值
      setTimeout(() => {
        context.commit('addOdd');
      }, 1000);
    },
    addOdd(context) {
      //这里必须写this才能够取到值
      if (context.state.count % 2 == 1) {
        context.commit('addOdd');
      }
    },
    increment(context) {
      //这里必须写this才能够取到值
      if (context.state.count > 0) {
        context.commit('increment');
      }
    },
    decrement(context) {
      console.log(context);
      context.commit('decrement');
    },
  },
  getters: {
    becomeTen(state) {
      return state.count * 10;
    },
  },
};
export default Count;
